package com.example.wudi.service.Impl;

import cn.dev33.satoken.stp.StpInterface;
import com.example.wudi.dao.RoleDao;
import com.example.wudi.entity.Permissions;
import com.example.wudi.entity.User;
import com.example.wudi.service.RoleService;
import com.example.wudi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class StpInterfaceImpl implements StpInterface {

    @Autowired
    private UserService userService;
    @Autowired
    private RoleService roleService;

    @Override
    public List<String> getPermissionList(Object o, String s) {
        final String s1 = o.toString();
        final int id = Integer.parseInt(s1);
        List<String> list = new ArrayList<>();

        final User userById = userService.findUserById(id);
        final String roleId = userById.getRoleId();
        final RoleDao roleByUserId = roleService.getRoleByUserId(roleId);
        final List<Permissions> permissionsList = roleByUserId.getPermissionsList();
        permissionsList.forEach(item -> {
            list.add(item.getPermissionsPath());
        });

        return list;
    }

    @Override
    public List<String> getRoleList(Object o, String s) {
        return null;
    }
}
